﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.ApplyCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.ApplyHandler
{
    public class GetAppBYIdCommandHandler : IRequestHandler<GetAppBYIdCommand, APIResult<List<Apply>>>
    {
        private readonly IBaseRepository<Apply> _ApplyRepository;

        public GetAppBYIdCommandHandler(IBaseRepository<Apply> applyRepository)
        {
            _ApplyRepository = applyRepository;
        }

        public async Task<APIResult<List<Apply>>> Handle(GetAppBYIdCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Apply>> result = new APIResult<List<Apply>>();
            result.Code = APIEnum.Success;
            result.Msg = "反填成功";

            var list = _ApplyRepository.GetAll().Where(p => p.ApplyId == request.ApplyId);

            result.Data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
